package com.xgq.drink.mapper;

import com.xgq.drink.entity.UserBehavior;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户行为表 Mapper 接口
 * </p>
 *
 * @author xgq
 * @since 2025-04-28
 */
public interface UserBehaviorMapper extends BaseMapper<UserBehavior> {
    @Select("SELECT DATE_FORMAT(created_at, '%Y-%m-%d') AS date, COUNT(*) AS count " +
            "FROM user_behavior " +
            "WHERE behavior_type = #{behaviorType} " +
            "AND created_at BETWEEN #{startTime} AND #{endTime} " +
            "GROUP BY DATE_FORMAT(created_at, '%Y-%m-%d')")
    List<Map<String, Object>> selectDailyViewCounts(@Param("startTime") LocalDateTime startTime,
                                                    @Param("endTime") LocalDateTime endTime,
                                                    @Param("behaviorType") Integer behaviorType);
}
